package model

import (
	"time"

	"github.com/jinzhu/gorm"
	uuid "github.com/satori/go.uuid"
)

type Post struct {
	ID         uuid.UUID `json:"id,omitempty"          gorm:"column:id;type:char(36);primary_key;not null"`
	UserId     uint      `json:"user_id,omitempty"     gorm:"column:user_id"`
	CategoryId uint      `json:"category_id,omitempty" gorm:"column:category_id"`
	Title      string    `json:"title,omitempty"       gorm:"column:title;type:varchar(50);not null"`
	HeadImg    string    `json:"head_img,omitempty"    gorm:"column:head_img"`
	Content    string    `json:"content,omitempty"     gorm:"column:content;type:text"`
	CreatedAt  time.Time `json:"created_at,omitempty"  gorm:"column:created_at;type:timestamp;not null"`
	UpdateAt   time.Time `json:"update_at,omitempty"   gorm:"column:update_at;type:timestamp;not null"`
}

func (post *Post) BeforeCreate(scope *gorm.Scope) error {
	return scope.SetColumn("ID", uuid.NewV4())
}
